import 'package:flutter/material.dart';

class NumInput extends StatelessWidget {
  NumInput({
    Key key,
    this.unit,
    this.fillColor: const Color(0xfff6f6f6),
//    this.fillColor: const Color(0xffff0000),
    this.onChange,
  }) : super(key: key);

  /// 单位
  final String unit;

  /// 输入框背景色
  final Color fillColor;

  /// 值改变
  final void Function() onChange;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 6),
      child: Flex(
        direction: Axis.horizontal,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Expanded(
            flex: 0,
            child: ConstrainedBox(
              constraints: BoxConstraints(maxWidth: 36),
              child: TextField(
                maxLines: 1,
                expands: false,
                textAlignVertical: TextAlignVertical.top,
                keyboardType: TextInputType.number,
                style: TextStyle(fontSize: 12),
                decoration: InputDecoration(
                    contentPadding:
                        const EdgeInsets.symmetric(horizontal: 2, vertical: 0),
                    filled: true,
                    fillColor: fillColor,
                    border: InputBorder.none,
                    labelText: null,
                    hintText: null,
                    prefixIcon: null),
              ),
            ),
          ),
          Expanded(
              flex: 1,
              child: Container(
                margin: EdgeInsets.only(left: 4),
                child: Text(unit),
              ))
        ],
      ),
    );
  }
}
